public class TrashCan {

	private final double capacity;
	private double trashAmount;

	public TrashCan(double capacity) {
		this.capacity = capacity;
		this.trashAmount = 0;
	}
	
	public double acceptTrash(double dumpWeight) {
		trashAmount = (trashAmount + dumpWeight) % capacity;
		return capacity - trashAmount;
	}

	/* Canonical Solution */
//	public double acceptTrash(double dumpWeight) {
//		if(trashAmount + dumpWeight >= capacity) {
//			trashAmount += dumpWeight - capacity;
//		} else {
//			trashAmount += dumpWeight;
//		}
//		return capacity - trashAmount;
//	}

	public static void main(String[] args) {

		System.out.println("TrashCan kitchen = new TrashCan(10.0);");
		TrashCan kitchen = new TrashCan(10.0);

		System.out.print("   kitchen.acceptTrash(2.5); -> Expect: 7.5, Result: ");
		System.out.println(  kitchen.acceptTrash(2.5));
		System.out.print("   kitchen.acceptTrash(3.5); -> Expect: 4.0, Result: ");
		System.out.println(  kitchen.acceptTrash(3.5));
		System.out.print("   kitchen.acceptTrash(6.0); -> Expect: 8.0, Result: ");
		System.out.println(  kitchen.acceptTrash(6.0));

		System.out.println("\nTrashCan bedroom = new TrashCan(3.0);");
		TrashCan bedroom = new TrashCan(3.0);

		System.out.print("   bedroom.acceptTrash(1.0) -> Expect: 2.0, Result: ");
		System.out.println(  bedroom.acceptTrash(1.0));
		System.out.print("   bedroom.acceptTrash(3.2) -> Expect: 1.8, Result: ");
		System.out.println(  bedroom.acceptTrash(3.2));
	}

}
